package com.morningstar.system.feign.interceptor;

import com.morningstar.common.utils.IPUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

@Slf4j
@AllArgsConstructor
@NoArgsConstructor
public class FeignInterceptor implements HandlerInterceptor {
    /**
     * 是否开启鉴权
     */
    private boolean isAuth = true;
    /**
     *
     */
    private boolean token;


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("FeignInterceptor");
        if (!isAuth) {
            return true;
        }
        String requestId = request.getHeader("X-Request-Id");
        String signature = request.getHeader("X-Signature");
        String requestIp = IPUtil.getIpAddress(request);
        log.info("{} {} {}", requestId, signature, requestIp);
        //TODO 检验IP 和  签名检验 内部鉴权
        return true;
    }
}
